Skip to content

fix(libcontainer): enforce check_proc_mount across all mount types and normalize destination - #3860

Closed
inanna-malick wants to merge 1 commit into
youki-dev:mainfrom
inanna-malick:fix/check-proc-mount-all-mounts
Closed

inanna-malick wants to merge 1 commit into
youki-dev:mainfrom
inanna-malick:fix/check-proc-mount-all-mounts

Conversation

@inanna-malick

Copy link
Copy Markdown

Summary

In Mount::setup_mount() (crates/libcontainer/src/rootfs/mount.rs), self.check_proc_mount(options.root, mount)? was previously only invoked inside the Some("proc" | "sysfs") match arm and was skipped in the wildcard _ => arm used by bind, tmpfs, and other non-proc/sysfs mount types. In addition, Mount::check_proc_mount() joined mount.destination() via rootfs.join_safely(dest) without normalizing . or .. segments first.

This PR:

  1. Calls self.check_proc_mount(options.root, mount)? in the _ => match arm of Mount::setup_mount() so non-proc/sysfs mounts targeting /proc or non-whitelisted paths under /proc are consistently rejected during setup_mount().
  2. Normalizes mount.destination() via Path::new(dest).normalize() in Mount::check_proc_mount() (and in the /dev destination comparison in setup_mount()) so destinations containing . or .. segments (e.g., /tmp/../proc/custom) cannot bypass the /proc prefix check.
  3. Adds a unit test (setup_mount_non_proc_fails_on_denied_proc_destination) covering both direct bind mounts and un-normalized tmpfs mount destinations targeting /proc/custom through Mount::setup_mount().

…d normalize destination

In Mount::setup_mount(), check_proc_mount() was only called inside the
Some("proc" | "sysfs") match arm and skipped in the wildcard _ => arm
used by bind, tmpfs, and other mount types. Additionally,
check_proc_mount() joined mount.destination() without normalizing '.' or
'..' segments first.

Call check_proc_mount() in the _ => arm of setup_mount() as well, and
normalize mount.destination() in check_proc_mount() and the /dev
comparison.

Signed-off-by: Inanna Malick <inanna@recursion.wtf>
Copilot AI balanced review requested due to automatic review settings October 30, 2026 01:30

Copilot AI left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

🟡 Changes recommended

The /proc restriction can be bypassed through symlinks or cgroup mounts, lexical normalization can make read-only mounts writable, and the regression test can pass on unrelated failures.

4 open issues
What changed in this PR

This PR strengthens mount-destination validation in libcontainer by extending /proc checks and normalizing paths before policy comparisons.

Changes:

  • Adds /proc validation to the fallback mount-type branch, including bind and tmpfs mounts.
  • Normalizes destinations for /proc checks and the /dev read-only exception.
  • Adds a regression test for direct and unnormalized destinations under /proc.
File Description
crates/​libcontainer/​src/​rootfs/​mount.rs Extends mount validation, normalizes destination comparisons, and adds regression coverage.

Review effort: Balanced

}
_ => {
if mount.destination() == Path::new("/dev") {
self.check_proc_mount(options.root, mount)?;
Comment on lines +225 to 226
if Path::new(mount.destination()).normalize() == Path::new("/dev") {
mount_option_config.flags &= !MsFlags::MS_RDONLY;
MountError::Other(err.into())
})?;
let dest_path = rootfs
.join_safely(Path::new(dest).normalize())
Comment on lines +1928 to +1938
.source(&custom)
.options(vec!["bind".to_string()])
.build()?;
assert!(m.setup_mount(&bind_mount, &options).is_err());

let unnormalized_mount = SpecMountBuilder::default()
.destination(PathBuf::from("/tmp/../proc/custom"))
.typ("tmpfs")
.source(PathBuf::from("tmpfs"))
.build()?;
assert!(m.setup_mount(&unnormalized_mount, &options).is_err());
@saku3

saku3 commented Oct 30, 2026

Copy link
Copy Markdown
Member

Thank you for the PR.

This issue is already addressed in #3846, so this PR is a duplicate.

I'll close this PR.

@saku3 saku3 closed this Oct 30, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants